package com.boarsoft.boar.sys.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.sys.SysRoleFuncBiz;
import com.boarsoft.boar.sys.entity.SysFunc;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@RestController
@RequestMapping("/sys/role/func")
public class SysRoleFuncAction {
	@Autowired
	private SysRoleFuncBiz sysRoleFuncBiz;

	@JsonIgnoreProperties({ "roles", "funcs" })
	@RequestMapping("/list.do")
	@Authorized(code = "sys.role.func.list")
	public ReplyInfo<Object> list(String roleId, String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<SysFunc> pr = sysRoleFuncBiz.list(roleId, key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

	/**
	 * 为指定角色授权或解除模块权限
	 * 
	 * @return
	 */
	@RequestMapping("/toggle.do")
	@Authorized(code = "sys.role.func.toggle")
	public ReplyInfo<Object> toggle(String key, String roleId, short status) {
		String[] fa = key.split(",");
		sysRoleFuncBiz.toggle(roleId, fa, status == 1);
		return ReplyInfo.SUCCESS;
	}
}